<?php

/**
 * Framework_Module_User_OpenIDServer
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Module
 * @filesource
 */

/**
 * Framework_Module_User_OpenIDServer
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @package Module
 */
class Framework_Module_User_OpenIDServer extends Framework_Module_User
{
	/**
	 * __construct
	 *
	 * Initializes the module: sets the default presenter, the allowed
	 * conrollers, and the allowed events
	 *
	 * @access 		public
	 * @return 		void
	 */
	public function __construct()
	{
		parent::__construct();
		$this->presenter = 'None';

	}

	/**
     * __default
     *
     * Process openID request
     *
     * @access 		public
     * @return 		mixed 		boolean true on success, PEAR_Error on failure
     */
	public function __default()
	{

		$openIDServer = Framework_OpenID::factoryServer();
		
		
		if (PEAR::isError($openIDServer)) {
			echo $openIDServer->getMessage();
		}
		
		if($this->session->openIDRequest) {
			$request = $this->session->openIDRequest;
		} else {
			$request = null;
		}

		$result = $openIDServer->start($request);

		if (PEAR::isError($result)) {

			unset($_SESSION['openIDRequest']);
			
			return $result;

		} else if ($openIDServer->doAuth()) {
			$openIDServer->generateResponse();

		} else {
			
			// Redirect to login
			Framework_Header::redirect(Framework::$request->getBaseHTTPPath().'/-/User/Login');
			
			
		}

	}

	/**
     * __destruct
     *
     *
     * @access 		public
     * @return 		void
     */
	public function __destruct()
	{
		parent::__destruct();
	}
}


?>
